package com.cc.controller;

import com.cc.entity.User;
import com.cc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 铁憨憨
 * @date 2021/2/5 21:47
 */
@RestController
public class UserController {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private UserService userService;
    @Value("${server.port}")
    private String port;
    @RequestMapping("getServiceList")
    public List<ServiceInstance> serviceInstanceList(){
        List<ServiceInstance> instanceList = discoveryClient.getInstances("student");
        return instanceList;
    }
    @GetMapping("getUserList")
    public List<User> getUserList(){
        return userService.getUserList();
    }
    @GetMapping("/getUserById/{id}")
    public String getUserById(@PathVariable("id")Integer id){
        User userById = userService.getUserById(id);
        return userById.toString()+"----->"+port;
    }
}
